package com.tzy.for10evalue.common;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class ResultEntity<T> {

    public static final String SC_INTERNAL_SERVER_ERROR = "500";

    private boolean success = true;

    private String resultMessage;

    private String resultCode = "0000";


    private T result;

    public static ResultEntity ok() {
        return new ResultEntity();
    }

    public static ResultEntity ok(String msg) {
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setResultMessage(msg);
        return resultEntity;
    }

    public static <T> ResultEntity<T> ok(T result) {
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setResult(result);
        return resultEntity;
    }

    public static ResultEntity error(String msg) {
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setResultCode(SC_INTERNAL_SERVER_ERROR);
        resultEntity.setSuccess(false);
        resultEntity.setResultMessage(msg);

        return resultEntity;
    }

}
